package com.luck.pf.common.logic;

import java.util.List;

import org.apache.commons.lang.time.DateUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.luck.emp.entity.EmpTPayment;
import com.luck.org.entity.SysLog;
import com.luck.pf.framework.logic.BaseLogic;
import com.luck.pf.util.CriteriaUtil;
import com.luck.pf.util.DateUtil;
import com.luck.pf.util.Page;

/**
 * 说明:
 * Copyright: Copyright (c) 2010
 * @author zhangwr 2011-8-9 下午08:47:15
 * @version 1.0
 */
public class CommonLogic extends BaseLogic implements ICommonLogic {
	public Page findLogsPage(CommonQry qry) throws Exception{
		Criteria criteria = super.baseDao.createCriteria(SysLog.class);
		CriteriaUtil.addGe(criteria, "operTime", qry.getStartDate());//订单日期
		CriteriaUtil.addLe(criteria, "operTime", DateUtil.getEndDateDay(qry.getEndDate()));
		CriteriaUtil.addEq(criteria, "logType", qry.getLogType());
		criteria.addOrder(Order.desc("id"));
		return baseDao.pagedQuery(criteria, qry.getPageNo(),qry.getPageSize());
	}
	public String checkPayment(Long orgId){
		StringBuffer bf = new StringBuffer();
		List<EmpTPayment> ls = super.baseDao.find(" FROM EmpTPayment WHERE deptId=? order by validDate desc", orgId);
		if(ls == null || ls.isEmpty()){
			bf.append("您的机构未有缴费记录，功能菜单被停用，请联系客服！");
		}else{
			EmpTPayment info = ls.get(0);
			if(info.getValidDate().before(DateUtils.addDays(DateUtil.getDate(), -1)))
				bf.append("你所在的机构使用费用已经过期，功能菜单被停用，请联系客服续费！");;
		}
		return bf.toString();
	}
}
